package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 协作参与者角色枚举
 *
 * <p>定义协作批阅中参与者的角色类型，包括发起人、参与者、观察者、专家等各种角色。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-13
 */
public enum ParticipantRole implements BaseEnum {

    /** 发起人 */
    INITIATOR("INITIATOR", "发起人"),

    /** 参与者 */
    PARTICIPANT("PARTICIPANT", "参与者"),

    /** 观察者 */
    OBSERVER("OBSERVER", "观察者"),

    /** 专家 */
    EXPERT("EXPERT", "专家"),

    /** 主持人 */
    MODERATOR("MODERATOR", "主持人"),

    /** 协调员 */
    FACILITATOR("FACILITATOR", "协调员"),

    /** 记录员 */
    RECORDER("RECORDER", "记录员"),

    /** 计时员 */
    TIMEKEEPER("TIMEKEEPER", "计时员");

    private final String code;
    private final String description;

    ParticipantRole(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static ParticipantRole fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Participant role code cannot be null or empty");
        }

        for (ParticipantRole role : values()) {
            if (role.getCode().equals(code)) {
                return role;
            }
        }
        throw new IllegalArgumentException("Unknown participant role code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static ParticipantRole fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Participant role description cannot be null or empty");
        }

        for (ParticipantRole role : values()) {
            if (role.getDescription().equals(description)) {
                return role;
            }
        }
        throw new IllegalArgumentException("Unknown participant role description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}